<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				uId:""
			})
		},
		methods:{
			getClockRecord(date){
				let _that = this
				_that.om.request(
					"tsupplementAttendance/getClockRecord",
					{
						
						userId:_that.uId,
						date:date
					}
				).then(res=>{
					if(!res.succeed){
						_that.om.toast(res.msg)
						_that.$refs.autoform.clear("dataInfo","supplementTime")
					}else{
						_that.$refs.autoform.formdata.attendanceRecord = res.value
					}
				})
			},
			verifyUser(date){
				let _that = this
				_that.om.request(
					"tsupplementAttendance/verifyUser",
					{
						userId:_that.uId,
						date:date
					}
				).then(res=>{
					if(!res.succeed){
						_that.om.toast(res.msg)
						_that.$refs.autoform.clear("dataInfo","supplementTime")
					}
				})
			},
			onSelectDate(item){
				let _that = this
				_that.verifyUser(item.value)
				_that.getClockRecord(item.value)
			},
			onSelectTime(time){
				let _that = this
				if(!_that.$refs.autoform.formdata.supplementDate){
					let title = _that.$refs.autoform.getEditorTitle("dataInfo","supplementDate")
					_that.om.toast("请先选择"+title)
					_that.$refs.autoform.clear("dataInfo","supplementTime")
					return
				}
				_that.om.request(
					"tsupplementAttendance/getRepairNode",
					{
						userId:_that.uId,
						date: _that.$refs.autoform.formdata.supplementDate,
						time: time
					}
				).then(res=>{
					if(res.succeed){
						_that.$refs.autoform.formdata.attendanceNodeName = res.value
					}
				})
			},
			initLoad(){
				let _that = this
				let pro1 = _that.om.request("tsupplementAttendance/getDateList",{userId:_that.uId})
				let pro2 = _that.om.request("tsysdict/getListByCode",{code:'38037'})
				Promise.all([pro1,pro2]).then(res=>{
					_that.$refs.autoform.changeEditor("dataInfo","supplementDate","data",configSelectData(res[0],"name",'value'))
					_that.$refs.autoform.initSelectIndex("dataInfo","supplementDate")
					_that.$refs.autoform.changeEditor("dataInfo","reasonId","data",configSelectData(res[1],"id",'dicname'))
					_that.$refs.autoform.initSelectIndex("dataInfo","reasonId")
				})
			}
		},
		onShow() {
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				_that.uId = e.userId
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
								_that.initLoad()
							}
						}
					})
				}
							
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
